import req from './axiosFun';
// const baseurl = 'http://118.89.86.21:8081/api'
const baseurl = 'http://localhost:8000/api'
    // const baseurl = 'apiServer'

const CryptoJS = require('crypto-js')

// 登录接口
export const login = (params) => {
    const key = CryptoJS.enc.Utf8.parse("sarasarasarasara");
    const iv = CryptoJS.enc.Utf8.parse("sarasarasarasara");
    const encrypted = CryptoJS.AES.encrypt(params.password, key, {
        iv: iv,
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    return req({
        url: baseurl + '/user/login',
        method: 'POST',
        data: {
            account: params.account,
            password: encrypted.toString()
        }
    })
};

//注册
export const regist = (params) => {
    const key = CryptoJS.enc.Utf8.parse("sarasarasarasara");
    const iv = CryptoJS.enc.Utf8.parse("sarasarasarasara");
    const encrypted = CryptoJS.AES.encrypt(params.password, key, {
        iv: iv,
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    return req({
        url: baseurl + '/user/sign-up',
        method: 'POST',
        data: {
            account: params.account,
            password: encrypted.toString()
        }
    })
};

//订单列表请求
export const orderlist = (data) => {
    return req({
        url: `${baseurl}/order/list?current=${data.currentPage}&size=${data.pageSize}`,
        method: 'GET',
    })
};

//订单信息提交
export const ordersave = (data) => {
    return req({
        url: baseurl + '/order/save',
        method: 'POST',
        data
    })
};

//期刊列表
export const journaldata = () => {
    return req({
        url: baseurl + '/magazine/list',
        method: 'GET',
    })
};

//行政区划
export const getAreas = (pid) => {
    return req({
        url: baseurl + '/area/getAreas?pid=' + pid,
        method: 'GET'
    })
};

//上传地址表格
export const uploadExcel = (data) => {
    return baseurl + '/order/address/import'
};

//上传发票表格
export const uploadInvoiceExcel = (data) => {
    return baseurl + '/order/invoice/import'
};

//下载模板
export const downloadTemplate = (template) => {
    return req({
        url: baseurl + '/order/download_template?templateName=' + template,
        method: 'GET',
        responseType: 'blob'
    })
};

//年份
export const getValue = (key) => {
    return req({
        url: baseurl + '/config/getValue?key=' + key,
        method: 'GET',
    })
};

export const rqCode = () => {
    return req({
        url: baseurl + '/user/getQrCode',
        method: 'GET',
    })
};

export const getUserInfo = (data) => {
    return req({
        url: baseurl + '/user/getOpenId?eventKey=' + data,
        method: 'GET',
    })
};

//选择页面数据获取
// export const selectdata =()=>{return axios.get('/api/index/wxapp.index/info')}